<?php

namespace App\Http\Controllers\Home;

use App\Models\Handroom;
use App\Services\Home\AttributeService;
use App\Services\Home\HandroomService;
use App\Services\Home\PropertyService;
use App\Services\Home\RegionService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HandroomController extends Controller
{
    protected $service;
    protected $properservice;
    protected $attrService;
    protected $regionService;

    public function __construct(HandroomService $handroomService,PropertyService $propertyService, AttributeService $attributeService,RegionService $regionService)
    {
        $this->service = $handroomService;
        $this->properservice = $propertyService;
        $this->attrService = $attributeService;
        $this->regionService = $regionService;
    }

    public function index(Request $request,$id)
    {
        // 市id
//        $id = $request->get('id');
        $areaid = isset($id)?$id:0;
        $city_info = $this->regionService->getCityInfo($areaid);
        //属性
        $area = $this->attrService->getAttributeById($areaid);
        // 朝向
        $direction = $this->attrService->getAttributeById(84);
        // 装修
        $renovation = $this->attrService->getAttributeById(47);
        //特色标签
        $tags = $this->attrService->getAttributeById(74);

        //搜索词
        $keyword = $request->get('keyword')??'';
        return view(env('DEFAULT_TEMPLATE').'.handroom',compact('area','areaid','direction','renovation','tags','city_info','keyword'));
    }

    public function data(Request $request) {
        return $this->service->data($request);
    }

    public function show($id)
    {
        $data = $this->service->getDetailById($id);
        $handroomNum = count($data->community->handroom->where('status','T'));
        $rentalhouseNum = count($data->community->rentalhouse->where('status','T'));
        return view(env('DEFAULT_TEMPLATE').'.hand_detail',compact('data','handroomNum','rentalhouseNum'));
    }

}
